<?php if(!defined('DB_NAME')) die();

// 此主题本是收费主题，由于作者消失一年多了，官网也没了。因为缙哥哥喜欢这个主题，所以破解公开该主题，并持续更新，欢迎访问缙哥哥的博客 - www.dujin.org 保留此条信息，以便查找最新Initial主题.
	
// functions
require ( dirname(__FILE__) . '/admin/admin.php' );
require ( dirname(__FILE__) . '/admin/seo.php' );
require ( dirname(__FILE__) . '/admin/meta.php' );
require ( dirname(__FILE__) . '/admin/rate.php' );
require ( dirname(__FILE__) . '/admin/img.php' );
require ( dirname(__FILE__) . '/admin/hack.php' );
require ( dirname(__FILE__) . '/admin/login.php' );
require ( dirname(__FILE__) . '/admin/notify.php' );
require ( dirname(__FILE__) . '/admin/editor.php' );
require ( dirname(__FILE__) . '/admin/article.php' );
require ( dirname(__FILE__) . '/admin/content.php' );
require ( dirname(__FILE__) . '/admin/comment.php' );
require ( dirname(__FILE__) . '/admin/option.php' );
require ( dirname(__FILE__) . '/admin/widget/widget.php' );
require ( dirname(__FILE__) . '/admin/custom.php' );
function get($e){ return stripslashes( get_option($e) ); }
function gets($e){ return stripslashes( get_settings($e) ); }

/**
* WordPress 防止机器人扫描邮箱[email]邮箱[/email]
* http://www.dujin.org/fenxiang/wp/5712.html
*/
function Bing_antispambot( $attr, $content ){
    return antispambot( $content );
}
add_shortcode( 'email', 'Bing_antispambot' );

/**
 * WORDPRESS 注册表单添加验证问题（支持多个随机问题）
 * http://www.dujin.org/fenxiang/wp/5710.html
 */
add_action( 'register_form', 'add_security_question' );
function add_security_question() { ?>
	<p>
	<label><?php _e('缙哥哥的博客域名是什么？答案[dujin.org]') ?><br />
		<input type="text" name="user_proof" id="user_proof" class="input" size="25" tabindex="20" /></label>
	</p>
<?php }
 
add_action( 'register_post', 'add_security_question_validate', 10, 3 );
function add_security_question_validate( $sanitized_user_login, $user_email, $errors) {
	// 如果没有回答
	if (!isset($_POST[ 'user_proof' ]) || empty($_POST[ 'user_proof' ])) {
		return $errors->add( 'proofempty', '<strong>错误</strong>: 您还没有回答问题（输入dujin.org即可）。'  );
	// 如果答案不正确
	} elseif ( strtolower( $_POST[ 'user_proof' ] ) != 'dujin.org' ) {
		return $errors->add( 'prooffail', '<strong>错误</strong>: 您的回答不正确（输入dujin.org即可）。'  );
	}
}

//增强默认编辑器
function Bing_editor_buttons($buttons){
	$buttons[] = 'fontselect';
	$buttons[] = 'fontsizeselect';
	$buttons[] = 'backcolor';
	$buttons[] = 'underline';
	$buttons[] = 'hr';
	$buttons[] = 'sub';
	$buttons[] = 'sup';
	$buttons[] = 'cut';
	$buttons[] = 'copy';
	$buttons[] = 'paste';
	$buttons[] = 'cleanup';
	$buttons[] = 'wp_page';
	$buttons[] = 'newdocument';
	return $buttons;
}
add_filter("mce_buttons_3", "Bing_editor_buttons");

//文章文本编辑器添加自定义按钮
function appthemes_add_quicktags() {
?>
<script type="text/javascript">
QTags.addButton( '评论可见', '评论可见', '[reply]','[/reply]' );
QTags.addButton( '自定义评论可见', '自定义评论可见', '[reply notice="自定义的提示信息"]','[/reply]' );
QTags.addButton( '邮箱', '邮箱', '[email]','[email]' );
</script>
<?php
}
add_action('admin_print_footer_scripts', 'appthemes_add_quicktags' );

/**
* WP主题INITIAL 用户的个人资料更新时发送邮件通知
* http://www.dujin.org/?p=5720
*/
function user_profile_update( $user_id ) {
        $site_url = get_bloginfo('wpurl');
        $user_info = get_userdata( $user_id );
        $to = $user_info->user_email;
        $subject = "个人资料已更新: ".$site_url."";
        $message = "您好 " .$user_info->display_name . "\n您的个人资料已更新！\n\n感谢您访问\n ".$site_url."";
        wp_mail( $to, $subject, $message);
}
add_action( 'profile_update', 'user_profile_update', 10, 2);

/**
* WP主题INITIAL 用户的个人资料更新时发送邮件通知
* http://www.dujin.org/?p=5720
*/
function user_profile_update_email_admin( $user_id ) {
        $site_url = get_bloginfo('wpurl');
        $user_info = get_userdata( $user_id );
        $to = get_option( 'admin_email' );
        $subject = $user_info->display_name." 的个人资料已更新";
        $message = "您好,管理员。用户 " .$user_info->display_name . " 的个人资料已更新！\n\n访问\n ".$site_url."";
        wp_mail( $to, $subject, $message);
}
add_action( 'profile_update', 'user_profile_update_email_admin', 10, 2);

/**
 * //缙哥哥自定义必应壁纸为登录页面背景
 * http://www.dujin.org/fenxiang/jiaocheng/3618.html
 */
function custom_login_head(){
$imgurl = 'http://www.dujin.org/sys/bing/1920.php';
if($imgurl){
    echo'<style type="text/css">body{background: url('.$imgurl.');background-attachment:fixed;width:100%;height:100%;background-image:url('.$imgurl.');background-attachment:fixed;-moz-background-size: 100% 100%;-o-background-size: 100% 100%;-webkit-background-size: 100% 100%;background-size: 100% 100%;-moz-border-image: url('.$imgurl.') 0;background-attachment:fixed;background-repeat:no-repeat\9;background-image:none\9;}h1 a { background-image:url('.get_bloginfo('url').'/favicon.ico)!important;width:32px;height:32px;-webkit-border-radius:50px;-moz-border-radius:50px;border-radius:50px;}#loginform {background-color:rgba(251,251,251,0.3)!important;}.login label,a{color:#000!important;}</style>';
}}
add_action('login_head', 'custom_login_head');
add_filter('login_headerurl', create_function(false,"return get_bloginfo('url');"));
add_filter('login_headertitle', create_function(false,"return get_bloginfo('name');"));

/**
 * 禁用修订版本，2015年3月5日更新
 * http://www.ludou.org/wordpress-post-id-continuous.html
 */
add_filter( 'wp_revisions_to_keep', 'specs_wp_revisions_to_keep', 10, 2 );
function specs_wp_revisions_to_keep( $num, $post ) {
   if ( 'post_type' == $post->post_type )
      $num = 0;

   return $num;
}
// 禁用自动保存，所以编辑长文章前请注意手动保存。
add_action( 'admin_print_scripts', create_function( '$a', "wp_deregister_script('autosave');" ) );
// WordPress 3.8测试有效
function keep_id_continuous(){
  global $wpdb;

  // 删掉自动草稿和修订版
  $wpdb->query("DELETE FROM `$wpdb->posts` WHERE `post_status` = 'auto-draft' OR `post_type` = 'revision'");

  // 自增值小于现有最大ID，MySQL会自动设置正确的自增值
  $wpdb->query("ALTER TABLE `$wpdb->posts` AUTO_INCREMENT = 1");  
}

add_filter( 'load-post-new.php', 'keep_id_continuous' );
add_filter( 'load-media-new.php', 'keep_id_continuous' );
add_filter( 'load-nav-menus.php', 'keep_id_continuous' );


/**
 * WP主题INITIAL回复可见的实现方法
 * http://www.dujin.org/?p=5680
 */
function reply_to_read($atts, $content=null) {     
        extract(shortcode_atts(array("notice" => '<p class="reply-to-read">温馨提示: 此处内容需要<a href="#respond" title="评论本文">评论本文</a>后才能查看.</p>'), $atts));     
        $email = null;     
        $user_ID = (int) wp_get_current_user()->ID;     
        if ($user_ID > 0) {     
            $email = get_userdata($user_ID)->user_email;     
            //对博主直接显示内容     
            $admin_email = "zwjzhangwuji@163.com"; //博主Email     
            if ($email == $admin_email) {     
                return $content;     
            }     
        } else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {     
            $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);     
        } else {     
            return $notice;     
        }     
        if (empty($email)) {     
            return $notice;     
        }     
        global $wpdb;     
        $post_id = get_the_ID();     
        $query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";     
        if ($wpdb->get_results($query)) {     
            return do_shortcode($content);     
        } else {     
            return $notice;     
        }     
    }     
      
    add_shortcode('reply', 'reply_to_read');   

//后台仪表盘订阅缙哥哥的博客最新资讯
function dashboard_custom_feed_output() {
     echo '<div class="rss-widget">';
     wp_widget_rss_output(array(
         'url' => 'http://www.dujin.org/feed/', //rss地址
          'title' => '查看网站的最新内容',
         'items' => 6,         //显示篇数
          'show_summary' => 1,  //是否显示摘要，1为显示
          'show_author' => 0,   //是否显示作者，1为显示
          'show_date' => 1  )); //是否显示日期
     echo '</div>';
}
function h_add_dashboard_widgets() {
    wp_add_dashboard_widget('example_dashboard_widget', '缙哥哥的博客 - 最新资讯', 'dashboard_custom_feed_output');
}
add_action('wp_dashboard_setup', 'h_add_dashboard_widgets' );